import WebHeader from '@/www/components/WebHeader'
import WebFooter from '@/www/components/WebFooter'
import { getQuoteOrder, payQuoteOrder } from '@/apiv2/quote'
import { Loading } from 'element-ui';

export default {
  components: { WebHeader, WebFooter },
  data() {
    return {
      user: undefined,
      order: undefined,
      payType: 'BALANCE',
    }
  },

  created(){
    const user = JSON.parse(localStorage.getItem('user'))
    this.user = user

    getQuoteOrder(this.$route.query.id).then(res => {
      console.log(res)
      this.order = res
    })
  },

  methods: {
      pay(){

        const loading = this.$loading({
          lock: true,
          text: '支付中，请勿关闭页面',
          spinner: 'el-icon-loading',
          background: 'rgba(0,0,0,0.7)'
        });

        const {order, payType} = this
        payQuoteOrder(order.id, { payType : payType}).then(res => {
          loading.close()
          this.$message.success('支付成功，订单审稿中，请稍后')
          this.$router.push({ path: '/' })
        }).catch(err => {
          loading.close()
          this.$message.error('支付失败')
        })
      }
  }
}
